//
//  WealthCollectionViewCell.m
//  UI_Project_A
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 GH. All rights reserved.
//

#import "WealthCollectionViewCell.h"
#import "TableViewCell.h"
#import "HandleData.h"
#import "ModelOfData.h"
#import "FlowNewModel.h"
#import <UIImageView+WebCache.h>
#import <MJRefresh.h>
#import "WealthTableCell.h"
#import <DKNightVersion.h>



#define WIDTH self.frame.size.width

@interface WealthCollectionViewCell ()<UITableViewDataSource,UITableViewDelegate,UIScrollViewDelegate>

@property (nonatomic ,retain)UITableView *tableview;
@property (nonatomic ,retain)NSMutableArray *arrayTitleWithNew;
@property (nonatomic ,retain)NSMutableArray *arrayCell;
@property (nonatomic ,retain)NSMutableArray *arrliudongImage;
@property (nonatomic ,retain)NSMutableArray *arrLabel;
@property (nonatomic ,retain)UIPageControl *page;
@property (nonatomic ,retain)UIScrollView *scroll;
@property (nonatomic ,retain)NSTimer *timer;
@property (nonatomic ,retain)NSMutableArray *arrimageOne;

@end

@implementation WealthCollectionViewCell


- (void)dealloc {
    
    [_tableview release];
    [_arrayCell release];
    [_arrayTitleWithNew release];
    [_arrliudongImage release];
    [_page release];
    [_scroll release];
    [_timer release];
    [_arrimageOne release];
    [super dealloc];
}





- (instancetype)initWithFrame:(CGRect)frame {
    
    self = [super initWithFrame:frame];
    if (self) {
        [self createTableviewWithFrame];
      
        [self dataWith];
        [self dataGHRefresh];
    }
    
    
    return self;
}


- (void)dataGHRefresh{

self.tableview.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
    [self dataWith];
    
}];



}





#pragma mark - Data

- (void)dataWith {
    
    self.arrimageOne = [NSMutableArray array];
    if (!self.arrayTitleWithNew) {
        self.arrayTitleWithNew = [NSMutableArray array];
    }
    
    [HandleData handleBlockWithurl:@"http://api.baiyue.baidu.com/sn/api/recommendlist" HTTPBody:@"wf=1&mid=8380B3E8589320AFC23220AB9C42D418%7C589951020642768&token=H4sIAAAAAAAAAB2XW5bkIAiGN5QH8AKyGk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J4PS%0ANXKeKZdT04iYb1JjHJ%2FFz8NBHOXprLgeKyhbTEoSfV5Gn138TU0g%2FdyycqV8nQTmudNz0mg5opG4%0AGBXznxLME4qFbEPChFpaFQ%2F805Qv5oUb7%2FVBRZAZN2pQIHGBoVNyfKjMYsWzTQwS%2Fs9EAcO5keVr%0A4I2sUy30euQYy9wqjFuvg0wWhDhxgEyRyFEu6iQCmcKq0d6a8gIeukhNmVCU247Jdx%2FultFNb5V6%0AqFllbvJ4ue8nPUExbENCJd2FaOoQ5k1Me4mBYjIlCAPGZ0ExwjhxlXxm9kMPOBHpSHkYbDKbdv5R%0ASwey5BoDfUu8mVf97shDNS%2BQ8sU3W4csnvkCfQ3HxohIGiG86yBLGCVlMv1%2BDArn%2BQ%2FrQdQiLHIT%0Ay2KVoKGTA4ekx6R3goJWczpl3%2F69uq8karkrGZpJypyHYqALOHRB4dgjZi3JFzwfKs1ox30V3BM7%0AUYymZmLlmG1EU%2Bx%2BPtrQckbmjvQdz4CBDFVnrbrADQ%2Fk0wYF50Q6%2FtnbZjiQXuZDSItIKV5zuMJF%0AoCvDt%2BP79vcGrsJElh%2BMNNVRG0S6%2BPzu6WU55iMqPhcwdPHf%2BV7mCaaVh2TCrLkQNBW0wI3mS%2BKt%0As9uDUSOh%2BNMeOngnZytWH6eTXFCKiZZrGImLErmpCR%2BZXN8fmgHhwcENAAA%3D%0A&withtoppic=1&mb=MX5&ln=200&from=news_smart&sv=5.8.4.0&an=20&ts=0&cuid=8380B3E8589320AFC23220AB9C42D418%7C589951020642768&topic=%E8%B4%A2%E7%BB%8F&type=info&manu=Meizu&ver=4&" addValue:@"application/x-www-form-urlencoded; charset=UTF-8" HTTPHeaderField:@"Content-Type" Block:^(id result) {
        NSDictionary *dic = [result objectForKey:@"data"];
        
        NSArray *arrNew = [dic objectForKey:@"news"];
        
        for (NSDictionary *dicNew in arrNew) {
            
            ModelOfData *model = [[ModelOfData alloc]init];
            NSString * str = [dicNew objectForKey:@"title"];
            
            if (str) {
                model.title = [dicNew objectForKey:@"title"];
                model.ts = [dicNew objectForKey:@"ts"];
                model.content = [dicNew objectForKey:@"content"];
                [self.arrayTitleWithNew addObject:model];
                [model release];
            }
            
            
            
            
            //image传值
            
            model.imageurls = [dicNew objectForKey:@"imageurls"];
            
            NSArray *arrimage = [dicNew objectForKey:@"imageurls"];
            
            
            
            for (NSDictionary *diciamge in arrimage) {
                model.url = [diciamge objectForKey:@"url"];
                
            }
            
        }
        [self.tableview.mj_header endRefreshing];
        [self.tableview reloadData];
    }];
    
  
}












#pragma mark - 添加每个Cell的tableview
- (void)createTableviewWithFrame{
 
    self.tableview = [[UITableView alloc] initWithFrame:self.bounds style:UITableViewStylePlain];
    
    
    [self addSubview:self.tableview];
    [self.tableview release];
    self.tableview.dataSource = self;
    self.tableview.delegate = self;
    
    self.tableview.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    [self.tableview registerClass:[TableViewCell class] forCellReuseIdentifier:@"poolTableviewCell"];
    [self.tableview registerClass:[WealthTableCell class] forCellReuseIdentifier:@"WealthTableCell"];
    
    
}










#pragma mark - tableViewDatasouce

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
      return self.arrayTitleWithNew.count;
}



- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ModelOfData *model = [self.arrayTitleWithNew objectAtIndex:indexPath.row];
    
    if (model.imageurls.count == 3) {
  
        WealthTableCell *cell = [tableView dequeueReusableCellWithIdentifier:@"WealthTableCell"];
        
        [cell passDataWithModl:model];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor],[UIColor colorWithWhite:0.247 alpha:1.000]);
        
        return cell;
    }else{
    
    TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"poolTableviewCell"];
    
    [cell passDataWithModel:model];
        
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.dk_backgroundColorPicker = DKColorWithColors([UIColor whiteColor],[UIColor colorWithWhite:0.247 alpha:1.000]);
        
        return cell;
  
    }
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    
    
    return 130;
}


- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    
    
    return 60;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
   ModelOfData *model = [self.arrayTitleWithNew objectAtIndex:indexPath.row];
    [[NSNotificationCenter defaultCenter]postNotificationName:@"push" object:nil userInfo:@{@"content":model}];


}





@end
